package com.miyake.dsp.converter;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;
import com.miyake.dsp.ScilabExecute;

public class MovingAverageScilab implements Processor {

	private ComplexArray source;
	private MovingAverageSetting setting;

	public MovingAverageScilab(MovingAverageSetting setting) {
		this.setting = setting;
	}
	
	@Override
	public void setSource(ComplexArray source) {
		this.source = source;
	}

	@Override
	public ComplexArray getSource() {
		return this.source;
	}

	@Override
	public ComplexArray getProcessed() {
		String command = "len=" + String.valueOf(setting.getLength()) + 
			";data1=data1(:);len_d=length(data1);tmp=[ones(len-1,1)*data1(1);data1;ones(len-1,1)*data1($)];h = ones(1,len)/len;ret = convol(h,tmp);side=(length(ret)-length(data1))/2;ret = ret(floor(side)+1:$-ceil(side));";

		return ScilabExecute.execute(command, source, "ret");
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
